package com.hy.lightning.boot.web.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * 监听器，初始化系统资源
 * @author root
 *
 */
public class BaseListener implements ServletContextListener {
	
	private ListenerHandler listenerHandler = new DefaultListenerHandler();
	
	public BaseListener () {}
	
	public BaseListener (ListenerHandler listenerHandler) {
		this.listenerHandler = listenerHandler;
	}
	
	@Override
	public void contextDestroyed(ServletContextEvent servletContextEvent) {
		System.out.println("web is close now!");
	}

	@Override
	public void contextInitialized(ServletContextEvent servletContextEvent) {
//		loadRealWebPath(servletContextEvent);//加载web项目路径
//		loadWebClassPath();//加载class路径
		listenerHandler.init();
	}

//	/**
//	 * 获取web class文件路径
//	 * @return
//	 */
//	public void loadWebClassPath() {
//		String webClassPath = ClassLoader.getSystemResource("").getPath();
//		System.setProperty("webClassPath", webClassPath);
//		System.out.println(String.format("[INFO  :0] %s webClassPath路径:%s", DateUtil.defaultDateToString(new Date()), System.getProperty("webClassPath")));
//	}
//	
//	/**
//	 * 获取wen项目真实路径
//	 * @param servletContextEvent
//	 * @return
//	 */
//	public void loadRealWebPath(ServletContextEvent servletContextEvent) {
//		System.setProperty("webRealPath", System.getProperty("user.dir")+File.separator);
//		System.out.println(String.format("[INFO  :0] %s webRealPath路径：%s", DateUtil.defaultDateToString(new Date()), System.getProperty("webRealPath")));
//	}
}
